/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import machine.Config;

/**
 *
 * @author admin
 */
public class Settings extends javax.swing.JDialog {

    Config cf;
    boolean ResetNeeded;
    
    /**
     * Creates new form Settings
     */
    public Settings() {
        initComponents();
        ResetNeeded = false;
    }
    
    public boolean isResetNeeded() {
        return ResetNeeded;
    }
    
    public void showDialog(Config conf) {
        cf = conf;
        setSize(210, 310);

         if (cf.grafik) {
            bGrafik.setSelected(true);
        }
         else {
            bGrafik.setSelected(false);            
        }
        if (cf.getMem64()) {
            b64KB.setSelected(true);
        }
        else {
            b32KB.setSelected(true);            
        }
        
        if (cf.getVideo()==cf.VIDEO64) {
            b64.setSelected(true);
        }
        else {
            b32.setSelected(true);            
        }

        switch(cf.getMain()) {
            case 0: {
                bNone.setSelected(true);
                break;
            }
            case 1: {
                bBasic6.setSelected(true);
                break;
            }
            case 2: {
                bBasicG.setSelected(true);
                break;
            }
        }

        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screen.width-getSize().width)/2, (screen.height-getSize().height)/2);
        setModal(true);
        setVisible(true);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        RamGroup = new javax.swing.ButtonGroup();
        VideoGroup = new javax.swing.ButtonGroup();
        MainGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        RamPanel = new javax.swing.JPanel();
        b32KB = new javax.swing.JRadioButton();
        b64KB = new javax.swing.JRadioButton();
        VideoPanel = new javax.swing.JPanel();
        b32 = new javax.swing.JRadioButton();
        b64 = new javax.swing.JRadioButton();
        MainPanel = new javax.swing.JPanel();
        bNone = new javax.swing.JRadioButton();
        bBasic6 = new javax.swing.JRadioButton();
        bBasicG = new javax.swing.JRadioButton();
        bGrafik = new javax.swing.JCheckBox();
        bOk = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Settings");
        setModal(true);
        setName("SettingsDlg"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        RamPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("RAM Size"));

        RamGroup.add(b32KB);
        b32KB.setText("32KB");
        b32KB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b32KBActionPerformed(evt);
            }
        });

        RamGroup.add(b64KB);
        b64KB.setText("64KB");
        b64KB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b64KBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout RamPanelLayout = new javax.swing.GroupLayout(RamPanel);
        RamPanel.setLayout(RamPanelLayout);
        RamPanelLayout.setHorizontalGroup(
            RamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RamPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(RamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(b32KB)
                    .addComponent(b64KB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        RamPanelLayout.setVerticalGroup(
            RamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RamPanelLayout.createSequentialGroup()
                .addComponent(b32KB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(b64KB))
        );

        VideoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Video"));

        VideoGroup.add(b32);
        b32.setText("32");
        b32.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b32ActionPerformed(evt);
            }
        });

        VideoGroup.add(b64);
        b64.setText("64");
        b64.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b64ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout VideoPanelLayout = new javax.swing.GroupLayout(VideoPanel);
        VideoPanel.setLayout(VideoPanelLayout);
        VideoPanelLayout.setHorizontalGroup(
            VideoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(VideoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(VideoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(b64)
                    .addComponent(b32))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        VideoPanelLayout.setVerticalGroup(
            VideoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(VideoPanelLayout.createSequentialGroup()
                .addComponent(b32)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(b64))
        );

        MainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Main module"));

        MainGroup.add(bNone);
        bNone.setText("None");
        bNone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bNoneActionPerformed(evt);
            }
        });

        MainGroup.add(bBasic6);
        bBasic6.setText("Basic 6");
        bBasic6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBasic6ActionPerformed(evt);
            }
        });

        MainGroup.add(bBasicG);
        bBasicG.setText("Basic G");
        bBasicG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBasicGActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MainPanelLayout = new javax.swing.GroupLayout(MainPanel);
        MainPanel.setLayout(MainPanelLayout);
        MainPanelLayout.setHorizontalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bBasicG)
                    .addComponent(bBasic6)
                    .addComponent(bNone))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        MainPanelLayout.setVerticalGroup(
            MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MainPanelLayout.createSequentialGroup()
                .addComponent(bNone)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bBasic6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bBasicG, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bGrafik.setText("Grafik");
        bGrafik.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                bGrafikStateChanged(evt);
            }
        });

        bOk.setText("Ok");
        bOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(RamPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(VideoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bGrafik)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bOk)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(RamPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(VideoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(MainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bGrafik)
                    .addComponent(bOk))
                .addGap(85, 85, 85))
        );

        getContentPane().add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

    private void bOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bOkActionPerformed
        setVisible(false);
        setModal(false);
    }//GEN-LAST:event_bOkActionPerformed

    private void b32KBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b32KBActionPerformed
        cf.setMem64(false);
        ResetNeeded = true;
    }//GEN-LAST:event_b32KBActionPerformed

    private void b64KBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b64KBActionPerformed
        cf.setMem64(true);
        ResetNeeded = true;
    }//GEN-LAST:event_b64KBActionPerformed

    private void b32ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b32ActionPerformed
        cf.setVideo(cf.VIDEO32);
        ResetNeeded = true;
    }//GEN-LAST:event_b32ActionPerformed

    private void b64ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b64ActionPerformed
        cf.setVideo(cf.VIDEO64);
        ResetNeeded = true;
    }//GEN-LAST:event_b64ActionPerformed

    private void bNoneActionPerformed(java.awt.event.ActionEvent evt) {
        cf.setMain(cf.NONE);
        ResetNeeded = true;
    }

    private void bBasic6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBasic6ActionPerformed
        cf.setMain(cf.BASIC6);
        ResetNeeded = true;
    }//GEN-LAST:event_bBasic6ActionPerformed

    private void bBasicGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBasicGActionPerformed
        cf.setMain(cf.BASICG);
        ResetNeeded = true;
    }//GEN-LAST:event_bBasicGActionPerformed

    private void bGrafikStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_bGrafikStateChanged
        if (bGrafik.isSelected()){cf.grafik=true;}else{cf.grafik=false;};
    }//GEN-LAST:event_bGrafikStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup MainGroup;
    private javax.swing.JPanel MainPanel;
    private javax.swing.ButtonGroup RamGroup;
    private javax.swing.JPanel RamPanel;
    private javax.swing.ButtonGroup VideoGroup;
    private javax.swing.JPanel VideoPanel;
    private javax.swing.JRadioButton b32;
    private javax.swing.JRadioButton b32KB;
    private javax.swing.JRadioButton b64;
    private javax.swing.JRadioButton b64KB;
    private javax.swing.JRadioButton bBasic6;
    private javax.swing.JRadioButton bBasicG;
    private javax.swing.JCheckBox bGrafik;
    private javax.swing.JRadioButton bNone;
    private javax.swing.JButton bOk;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
